﻿using Rabbit.Domain.Entity;
using Rabbit.Domain.IRepository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Rabbit.Domain.Repository
{
    public class BreedRepository: IBreedRepository
    {
        private readonly RbacContext _context;

        public BreedRepository(RbacContext context)
        {
            _context = context;
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="breed"></param>
        /// <returns></returns>
        public int GetBreedAdd(Breed breed)
        {
            var list=_context.Breeds.Add(breed);
            return _context.SaveChanges();
        }

        /// <summary>
        /// 反填
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public dynamic GetBreedFind(int id)
        {
            var list=_context.Breeds.FirstOrDefault(x=>x.BreedId == id);
            return list;
        }

        /// <summary>
        /// 显示
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public List<Breed> GetBreedShow(int id)
        {
            var list=_context.Breeds.Where(x=>x.GoodInfoId == id).ToList();
            return list;
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="breed"></param>
        /// <returns></returns>
        public int GetBreedUpd(Breed breed)
        {
          var list=_context.Breeds.FirstOrDefault(x=>x.BreedId==breed.BreedId);
            list.BreedBrand=breed.BreedBrand;
            list.GoodInfoId=breed.GoodInfoId;
            list.BreedId=breed.BreedId;
            list.BreedName=breed.BreedName;
            list.BreedPut=breed.BreedPut;
            list.BreedCome=breed.BreedCome;
            list.BreedDay=breed.BreedDay;
            list.BreedPerson=breed.BreedPerson;
            _context.Breeds.Update(list);
            return _context.SaveChanges();

        }


        #region   保健

        /// <summary>
        /// 保健添加
        /// </summary>
        /// <param name="health"></param>
        /// <returns></returns>
        public int GetHealthAdd(Health health)
        {
            var list=_context.Healths.Add(health);
            return _context.SaveChanges();
        }

        /// <summary>
        /// 保健删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int GetHealthDel(int id)
        {
            var list=_context.Healths.FirstOrDefault(x=>x.HealthId==id);
            list.IsDel = 1;
            return _context.SaveChanges();
        }



        /// <summary>
        /// 显示
        /// </summary>
        /// <returns></returns>
        public List<Health> GetHealthShow()
        {
            var list=_context.Healths.Where(x=>x.IsDel==0).ToList();
            return list;
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="health"></param>
        /// <returns></returns>
        public int GetHealthUpd(Health health)
        {
            var list=_context.Healths.Update(health);
            return _context.SaveChanges();
        }

        /// <summary>
        /// 反填
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public dynamic GetHealthFind(int id)
        {
            var list=_context.Healths.FirstOrDefault(x=>x.HealthId == id);
            return list;
        }


        #endregion

        /// <summary>
        /// 显示
        /// </summary>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public List<Ycompany> GetYcompanShow()
        {
            var list=_context.Ycompanies.ToList();
            return list;
        }

        /// <summary>
        /// 反填
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public dynamic GetYcompanyFind(int id)
        {
            var list=_context.Ycompanies.FirstOrDefault(x=>x.CompanyId == id);
            return list;
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="ycompany"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public int GetYcompanyUpd(Ycompany ycompany)
        {
            var list=_context.Ycompanies.Update(ycompany);
            return _context.SaveChanges();
        }

        /// <summary>
        /// 动检添加
        /// </summary>
        /// <param name="animal"></param>
        /// <returns></returns>
        public int GetAnimalAdd(Animal animal)
        {
            var list=_context.Animals.Add(animal);
            return _context.SaveChanges();
        }

        /// <summary>
        /// 动检显示
        /// </summary>
        /// <returns></returns>
        public List<Animal> GetAnimalShow()
        {
            var list=_context.Animals.ToList();
            return list;
        }

        public int GetYimgAdd(Yimg yimg)
        {
            var list = _context.Add(yimg);
            return _context.SaveChanges();
        }

        public List<Yimg> GetYimgShow()
        {
            var list=_context.Yimgs.ToList();
            return list; 
        }
    }
}
